#!/usr/bin/env python
# encoding: utf-8
"""
transformation.py

Created by daspork on 2012-04-21.
Copyright (c) 2012 Knuckledragger Games. All rights reserved.
"""

from euclid import *
from OpenGL.GL import *

class Transformation(object):
    """A simple clone of the unity transformation cause I <3 it."""
    def __init__(self):
        self._position = Point3(0,0,0);
        self._rotation = Quaternion();


    def DoTransformation(self, parentTransform=None):
        angle, axis = self._rotation.get_angle_axis()
        x,y,z = self._rotation.get_euler()
        glTranslate(*self._position.xyz)
        glRotate(angle * (180/3.1415), axis.x, axis.y, axis.z)


    def Rotate(self, q):
        #print "Doing Rotate", self._rotation, self._rotation.get_angle_axis()
        self._rotation *= q


    def Translate(self, vector):
        self._position += vector


    @property
    def Position(self):
        return self._position


    @property
    def Rotation(self):
        return self._rotation


    @property
    def Forward(self):
        return (self._rotation * Vector3(0, 0, 1)).normalized()


    @property
    def Back(self):
        return (self._rotation * Vector3(0, 0, -1)).normalized()


    @property
    def Left(self):
        return (self._rotation * Vector3(1, 0, 0)).normalized()


    @property
    def Right(self):
        return (self._rotation * Vector3(-1, 0, 0)).normalized()


    @property
    def Up(self):
        return (self._rotation * Vector3(0, 1, 0)).normalized()


    @property
    def Down(self):
        return (self._rotation * Vector3(0, -1, 0)).normalized()

